package com.glorious.gcontacts.contacts.spring.controllers;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.glorious.gcontacts.contacts.spring.services.GoogleContactsService;
import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserServiceFactory;

@Controller
@RequestMapping("/")
public class MainContactsController
{
	private GoogleContactsService googleContactsService;
	
	@Autowired
	public void setGoogleContactsService(GoogleContactsService googleContactsService)
	{
		this.googleContactsService = googleContactsService;
	}

	@RequestMapping("/list")
	public ModelAndView list() throws Exception
	{
		ModelAndView mav = new ModelAndView("list");
		
		/*String CONSUMER_KEY = "www.gloriouscontacts.com";
		String CONSUMER_SECRET = "pFXnB65KR4Q3hzwE8hUCC9xK";
		String AUTH_TOKEN = "1/m2tyHgFzQIlAjj0LClVZWE26-tdk7B58qFZICxFHV6o";
		String AUTH_TOKEN_SECRET = "v1mbyKtLeUDrvA9z9ODvHLiB";
		

		GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
		oauthParameters.setOAuthConsumerKey(CONSUMER_KEY);
		oauthParameters.setOAuthConsumerSecret(CONSUMER_SECRET);
		oauthParameters.setOAuthToken(AUTH_TOKEN);
		oauthParameters.setOAuthTokenSecret(AUTH_TOKEN_SECRET);
		ContactsService service = new ContactsService("test");
		service.setOAuthCredentials(oauthParameters, new OAuthHmacSha1Signer());
		ContactGroupFeed feed = service.getFeed(new URL("https://www.google.com/m8/feeds/groups/default/full"), ContactGroupFeed.class);
		*/
		
		
		
		User user = UserServiceFactory.getUserService().getCurrentUser();
		mav.addObject("groups",googleContactsService.getGroups(user));
		return mav;
	}
}
